package com.itrencai.d13_thread.threadpoor;

import java.util.concurrent.*;

//自定义一个线程池对象并测试其特性
public class ThreadPoorDemo1 {
    public static void main(String[] args) {
        //1.创建线程池对象
/*        public ThreadPoolExecutor( int corePoolSize,核心线程数量
                                     int maximumPoolSize,最大线程数量
                                     long keepAliveTime,最大时间
                                     TimeUnit unit,
                                     BlockingQueue<Runnable> workQueue,
                                     ThreadFactory threadFactory,
                                     RejectedExecutionHandler handler)*/
        ExecutorService pool=new ThreadPoolExecutor(3,5,
                6,TimeUnit.SECONDS,new ArrayBlockingQueue<>(5),Executors.defaultThreadFactory(),
                new ThreadPoolExecutor.AbortPolicy());

        //2.给任务线程池处理
        Runnable target=new MyRunnable();
        pool.execute(target);
        pool.execute(target);
        pool.execute(target);
        pool.execute(target);
        pool.execute(target);
        pool.execute(target);

        //关闭线程池
        pool.shutdown();//等待全部任务执行完毕之后再关闭（建议使用）
        //poor.shutdownNow();//立即关闭，即使任务没有完成，也丢失任务



    }
}
